﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <style>
        /*.layui-table-cell {
            height: auto;
            line-height: initial;
        }*/
        .layui-btn {
            margin-left: 0px !important;
        }
    </style>
    <script src="~/js/CommonHelper.js"></script>
    <script type="text/javascript">
        var table;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table;

            table.render({
                elem: '#table-datalist'
                , url: '/Console/SystemConfig/WxMsgGetListJson'
                , limit: 10
                , title: '数据数据表'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'info', title: '菜单名称',}
                    , { field: 'menuname', title: '消息名称',}
                    , {
                        field: 'status', title: '是否显示', width: 150, templet: function (res) {
                            if (res.status)
                                return '<input type="checkbox" name="status" lay-skin="switch" lay-text="显示|不显示" lay-filter="table-state" value="' + res.id + '" checked="checked">'
                            else
                                return '<input type="checkbox" name="status" lay-skin="switch" lay-text="显示|不显示" lay-filter="table-state" value="' + res.id + '">'
                        }
                    }
                    , { fixed: 'right', title: '操作', width: 200, toolbar: '#table-datalist-bar' }
                ]]
                , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                , parseData: function (res) {
                    //console.log(res);
                }
            });
            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    var index = layer.open({
                        type: 2,
                        title: '编辑数据',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['800px', '600px'],
                        content: '/Console/SystemConfig/WxMessnagePage?id=' + data.id
                    });
                    layer.full(index);
                }
            });
            var typeval = 0, sourceval = 0;
            //监听锁定操作
            form.on('switch(table-state)', function (obj) {
                $.ajax({
                    type: "POST",
                    url: "/Console/SystemConfig/UpdateState",
                    data: { id: this.value, intState: obj.elem.checked }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            layer.msg("操作成功", { icon: 1, time: 1000 }, function () {
                                table.reload("table-datalist");
                            });
                        } else if (item.code == 1) {
                            layer.msg(item.msg, { icon: 2 });
                        } else {
                            layer.msg("保存失败", { icon: 0 });
                        }
                        layer.closeAll('loading');
                    }
                });
            });
            /* 监听提交 */
            form.on('submit(search)', function (data) {
                var params = [];
                params["type"] = $("select[name='type']").val();
                table.reload('table-datalist', {
                    where: params,
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                });
                return false;
            });
        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <div class="layui-card">
                <div class="layui-card-header">数据管理</div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                    <script type="text/html" id="table-datalist-bar">
                        <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>